<?php
namespace  app\models;
require_once 'BaseModel.php';

class Users  extends BaseModel{
	
	const USER_TYPE_STAFF = 'staff';
	
	const USER_TYPE_PARTNER = 'partner';
	
	const USER_TYPE_CONTRACTOR = 'contractor';
	
	/**
	 * jianhaomai
	 * @param unknown_type $name
	 * @return unknown|NULL
	 */
	public static function getUser($name){
		$con = self::pdo_con();
		#$sql = 'select * from users where name ="' . mysql_real_escape_string($name). '" order by id asc limit 1';
		$sql = 'select * from users where name ="' . ($name). '" order by id asc limit 1';
		foreach ($con->query($sql) as $row) {
			return $row;
// 			array (size=8)
// 			'id' => string '1' (length=1)
// 			0 => string '1' (length=1)
// 			'name' => string 'ss' (length=2)
// 			1 => string 'ss' (length=2)
// 			'password' => string 'ss' (length=2)
// 			2 => string 'ss' (length=2)
// 			'created_at' => string '2016-07-27 13:21:50' (length=19)
// 			3 => string '2016-07-27 13:21:50' (length=19)
        }
        return null;
	}

	public static function getUserById($id){
		$con = self::pdo_con();
		$sql = 'select * from users where id="' .intval($id). '" limit 1';
		foreach ($con->query($sql) as $row) {
			return $row;
        }
        return null;
	}
}
